package com.rybbaby.tss.tasks.core.task.dao.imp;

import com.rybbaby.tss.tasks.core.task.dao.ITssMemberPackageDao;
import com.rybbaby.tss.tasks.core.task.entity.TssMemberPackage;
import com.rybbaby.tss.tasks.core.web.dao.imp.GenericDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 会员课时包数据库操作实现
 *
 * @author 雷春琼
 *
 * @createDate 2017-08-10 上午12:04:35
 */
@Repository
public class TssMemberPackageDaoImp extends GenericDao<TssMemberPackage> implements ITssMemberPackageDao {

    /**
     * 亲子每日考勤扣除课时
     * @param params
     * @return
     */
    @Override
    public boolean deductiveHours(List<Object[]> params) {
        String sql = "UPDATE tss_member_package\n" +
                "SET unusedClassHour = unusedClassHour - ?,\n" +
                " consumptionClassHour = consumptionClassHour + ?\n" +
                "WHERE\n" +
                "\ttss_member_package.id = ?";

        return this.batchUpdate(sql,params);
    }

    @Override
    public boolean remediationClassHour(ArrayList<Object[]> params) {
        String sql = "UPDATE tss_member_package\n" +
                "SET unusedClassHour = unusedClassHour - ? ,\n" +
                "consumptionClassHour = consumptionClassHour + ? ,\n" +
                "remediationClassHour = remediationClassHour + ? \n" +
                "WHERE\n" +
                "\ttss_member_package.id = ?";

        return this.batchUpdate(sql,params);
    }

    @Override
    public boolean transitionAttendance(ArrayList<Object[]> params) {
        String sql = "UPDATE tss_member_package\n" +
                "SET noAttendanceDay = noAttendanceDay - 1 ,\n" +
                "attendedDay = attendedDay + 1 \n" +
                "WHERE\n" +
                "\ttss_member_package.id = ?";

        return this.batchUpdate(sql,params);
    }

    @Override
    public boolean absentDays(ArrayList<Object[]> params) {
        String sql = "UPDATE tss_member_package\n" +
                "SET attendedDay = attendedDay + 1 \n" +
                "WHERE\n" +
                "\ttss_member_package.id = ?";

        return this.batchUpdate(sql,params);
    }

    @Override
    public Integer updatePackageValidity() {
        String sql = "update  tss_member_package  set surplusValidDate=surplusValidDate-1 where packageStatus=1 and surplusValidDate!=0";
        return this.updateBySql(sql);
    }
}
